package com.none.usercenter.once;

import com.none.usercenter.mapper.UserMapper;
import com.none.usercenter.model.domain.User;
import com.none.usercenter.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;

import java.util.ArrayList;

@Component
public class InsertUsers {

    @Resource
    private UserMapper userMapper;

    @Autowired
    private UserService userService;

    /**
     * 批量插入用户
     */
    //initialDelay = 5000: 首次执行延迟5秒（5000毫秒）,fixedRate = Long.MAX_VALUE: 固定速率执行，间隔为Long的最大值
//    @Scheduled(initialDelay = 5000,fixedRate = Long.MAX_VALUE)
    public void insertUsers() {
        StopWatch stopWatch = new StopWatch();
        System.out.println("goodgood");
        stopWatch.start();
        final int INSERT_NUM = 10000;
        ArrayList<User> userArrayList = new ArrayList<>();
        for (int i = 0; i < INSERT_NUM; i++) {
            User user = new User();
            user.setUsername("假鱼皮");
            user.setUserAccount("fakeyupi");
            user.setAvatarurl("https://static.deepseek.com/user-avatar/Uy4wL-avp8bm5G1Q8JPDhdFj");
            user.setGender(0);
            user.setUserPassword("123456");
            user.setPhone("123");
            user.setEmail("123@qq.com");
            user.setUserStatus(0);
            user.setUserRole(0);
            user.setPlanetCode("111111");
            user.setTags("[]");
            userArrayList.add(user);
        }
        //批量插入
        userService.saveBatch(userArrayList,100);
        stopWatch.stop();
        System.out.println(stopWatch.getTotalTimeMillis());
    }
}
